package com.twu.biblioteca;

import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 * User: ama
 * Date: 14/10/13
 * Time: 6:38 PM
 * This class interacts with predefined user list to provide information
 * about users to the app.
 */
public class User {
    static HashMap<String, User> registeredUsers;
    private UserDetails userDetails;
    private String password;


    public User() {
        createUsers();
    }

    private User(String password, String realName, String email, String phoneNumber) {
        this.password = password;
        this.userDetails = new UserDetails(realName, email, phoneNumber);
    }

    public static HashMap<String, User> createUsers() {
        registeredUsers = new HashMap<String, User>();
        registeredUsers.put("111-1111", new User("ama", "Ama Doe", "ama@somedomain.com", "+1(123)456-7890"));
        return registeredUsers;
    }

    public User login(String userName, String password) {
        return areUserDetailsValid(userName, password);

    }

    private User areUserDetailsValid(String userName, String password) {
        User user = registeredUsers.get(userName);
        if (user != null && user.password.equals(password)) {
            return user;
        }
        return null;

    }

    public String viewMembershipDetails() {
        return this.userDetails.toString();
    }
}
